<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>出租单管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	 <link rel="stylesheet" href="${ctx}/resources/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<link rel="stylesheet" type="text/css" href="${ctx}/resources/easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/resources/css/wu.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/resources/css/icon.css" />
<script type="text/javascript" src="${ctx}/resources/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/easyui/datagrid-detailview.js"></script>
<script type="text/javascript" src="${ctx}/resources/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resources/zTree/js/jquery.ztree.core.js"></script>

  </head>
  
  <body>
    <!-- 查询条件开始 -->
	<div class="easyui-panel" data-options="title:'查询条件',iconCls:'icon-search'" style="width:100%;">
		<form id="searchFrm" method="get">
			<table width="100%" cellpadding="10" >
				<tr>
					<td width="33%">
					<input class="easyui-textbox" name="rentid"
							data-options="label:'出租单号:',labelPosition:'left',labelAlign:'right'"
							style="width:80%;">
					</td>
					<td width="33%"> 
					<input class="easyui-textbox" name="carnumber"
							data-options="label:'车辆牌号:',labelPosition:'left',labelAlign:'right'"
							style="width:80%;">
					</td>
					<td width="33%">
					<input class="easyui-textbox" name="identity"
							data-options="label:'身份证号:',labelPosition:'left',labelAlign:'right'"
							style="width:80%;">
					</td>
				</tr>
				<tr>
					<td width="33%">
					<input class="easyui-textbox" name="begindate"
							data-options="label:'起租时间:',labelPosition:'left',labelAlign:'right'"
							style="width:80%;">
					</td>
					<td width="33%">
					<input class="easyui-textbox" name="returndate"
							data-options="label:'还车时间:',labelPosition:'left',labelAlign:'right'"
							style="width:80%;">
					</td>
					<td width="33%">
						<label class="textbox-label" style="text-align: right;">
        				出租状态:
        			</label>
           			 <input class="easyui-radiobutton" name="rentflag" value="0">&nbsp;&nbsp;未归还&nbsp;&nbsp;&nbsp;&nbsp;
           			 <input class="easyui-radiobutton" name="rentflag" value="1">&nbsp;&nbsp;已归还
					</td>
				</tr>
				<tr>
					<td colspan="3" align="center">
						<a href="javascript:void(0)" class="easyui-linkbutton" onclick="doSearch()" data-options="iconCls:'icon-search'">查询</a>
						<a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#searchFrm').form('clear')" data-options="iconCls:'icon-reload'">重置</a>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<!-- 查询条件结束 -->
	 <div style="height: 2px"></div>
	 <!-- 数据表格开始 -->
    <table id="table" class="easyui-datagrid" style="width:100%;height:300px">
    </table>
	<div id="tb">
	<a href="javascript:void(0)" class="easyui-linkbutton" id="updateRent" data-options="iconCls:'icon-edit',plain:true">修改出租单</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" id="deleteRent" data-options="iconCls:'icon-remove',plain:true">删除出租单</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" id="exportRent" data-options="iconCls:'icon-page-excel',plain:true">导出出租单</a>
	</div>
	<!-- 数据表格结束  -->
		<!-- 添加和修改用户的弹出层 开始 -->
	<div id="dlg" class="easyui-dialog" style="width:500px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
        <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:10px">
                <input name="rentid" id="rentid" class="easyui-textbox" required="true" label="出租单号:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="identity" id="identity" class="easyui-textbox" required="true" label="身份证号:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="carnumber" id="carnumber"  class="easyui-textbox" required="true" label="出租车牌:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="price" class="easyui-textbox" required="true"  label="出租价格:" style="width:100%">
            </div>
             <div style="margin-bottom:10px">
                <input name="begindate" class="easyui-datebox" required="true"  label="起租时间:" style="width:100%">
            </div>
             <div style="margin-bottom:10px">
                <input name="returndate" class="easyui-datebox" required="true"  label="还车时间:" style="width:100%">
            	<input name="rentflag" type="hidden" >
            </div>
             <div style="margin-bottom:10px">
                <input name="opername" id="opername"  class="easyui-textbox" required="true"  label="操作员:" style="width:100%">
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveRent()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
	
  </body>
  <script type="text/javascript">
  
//加载表格数据
	$("#table").datagrid({
		title:'出租单列表',
		singleSelect:true,
		collapsible:true,
      fitColumns:true,
      pagination:true,
      rownumbers:true,
      toolbar:'#tb',
      url:'${ctx}/rent/loadAllRent.action',
      columns:[[
                {field:'rentid',title:'出租单号',align:'center',width:100},
                {field:'price',title:'租车价格',align:'center',width:100},
                {field:'begindate',title:'起始时间',align:'center',width:100},
                {field:'returndate',title:'归还时间',align:'center',width:100},
                {field:'rentflag',title:'租车状态',align:'center',width:100,formatter:function(value){
              	  if(value==0){
               		 return "<font color=red>未归还</font>"; 
               	  }else{
               		  return "<font color=green>已归还</font>"; 
               	  }
                }},
                {field:'identity',title:'身份证号',align:'center',width:100},
                {field:'carnumber',title:'车辆号牌',align:'center',width:100},
                {field:'opername',title:'业务人员',align:'center',width:100}
            ]],
           
	});
		//查询
		function doSearch(){
			var params=$("#searchFrm").serialize();
			$("#table").datagrid({
				url:'${ctx}/rent/loadAllRent.action?'+params
			});
		};
  
		
		//打开修改的弹出层
		$("#updateRent").click(function(){
			//得到当前行
			var row=$("#table").datagrid('getSelected');
			if(row){
				if(row.rentflag==1){
					$.messager.show({
						title:'提示',
						msg:'本单车辆已归还，请勿修改'
					});
				}else{
				$("#dlg").dialog("open").dialog('setTitle','修改车辆');
				//表单数据装载
				$("#fm").form("load",row);
				//设置carnumber只读
				$("#rentid").textbox({readonly:true});
				$("#identity").textbox({readonly:true});
				$("#carnumber").textbox({readonly:true});
				$("#opername").textbox({readonly:true});
				url="${ctx}/rent/updateRent.action";
				}
			}else{
				$.messager.show({
					title:'提示',
					msg:'请选中操作行'
				});
			}
		});
		
		
		//保存
		function saveRent(){
			$.messager.progress();	// 显示进度条
			$('#fm').form('submit', {
				url: "${ctx}/rent/updateRent.action",                                 //数据提交地址  user/addCar.action
				onSubmit: function(){
					var isValid = $(this).form('validate');//对表单里面的required:true和vailType的数据进行验证
					if (!isValid){
						$.messager.progress('close');	    // 如果验证失败关闭进度条
					}
					return isValid;	                  //返回验证结果
				},
				success: function(obj){               //如果提交成功之后回调的方法
					$.messager.progress('close');	  // 关闭进度条
                    var result = eval('('+obj+')');    //把obj的josn字符串转成js认识的json对象
					$.messager.show({
						title:'提示',
						msg:result.msg
					});
					$("#table").datagrid("reload");    //刷新数据表格
					$("#dlg").dialog("close");         //关闭弹出层
				}
			});
		}
		
		
		//删除
		//删除出租单
		$("#deleteRent").click(function(){
			//得到当前行
			var row=$("#table").datagrid('getSelected');
			if(row){
				$.messager.confirm('提示','你确定要删除【'+row.rentid+'】这个出租单吗?',function(r){
                    if (r){
                        $.post('${ctx}/rent/deleteRent.action',{rentid:row.rentid,carnumber:row.carnumber},function(result){
                        	//var resu = eval('('+result+')');    为啥没用
                                $.messager.show({    
                                    title: '提示',
                                    msg: result.msg
                                });
                                $("#table").datagrid("reload");//刷新表格
                        },'json');
                    }
                });
			}else{
				$.messager.show({
					title:'提示',
					msg:'请选中操作行'
				});
			}
		});
		
		//导出出租单
		$("#exportRent").click(function(){
			//得到当前行
			var row=$("#table").datagrid('getSelected');
			if(row){
			//不用异步请求
			window.location.href="${ctx}/rent/exportRent.action?rentid="+row.rentid;
			}else{
				$.messager.show({
					title:'提示',
					msg:'请选中操作行'
				});
			}
		})
		
  </script>
  
</html>
